#include "adr/Metadata/Validators/RequiredAttribute.h"
#include "adr/Metadata/BaseProperty.h"

namespace adr {
	RequiredAttribute::RequiredAttribute(bool isRequired)
		: ValidationAttribute("Required"), isRequired(isRequired) {}

	RequiredAttribute::~RequiredAttribute() {}

	bool RequiredAttribute::Validate(BaseProperty& prop) {
		if (!this->isRequired || prop.HasValue()) {
			return true;
		}

		this->AddValidationError(prop, "The field " + prop.GetDisplayName() + " is required.");
		return false;
	}
}